import React from 'react';
// import { Table,Popconfirm } from 'antb';
import { Table, Popconfirm } from 'antd';


class Student extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            columns: [
                {
                    title: '姓名',
                    dataIndex: 'name',
                    key: 'name',
                },
                {
                    title: '年龄',
                    dataIndex: 'age',
                    key: 'age',
                },
                {
                    title: '性别',
                    dataIndex: 'sex',
                    key: 'sex',
                },
                {
                    title: '操作',
                    dataIndex: 'edit',
                    render: (text, record) =>
                        this.state.data.length >= 1 ? (
                            <Popconfirm title="Sure to delete?" onConfirm={() => this.handleDelete(record.key)}>
                                <a>Delete</a>
                            </Popconfirm>
                        ) : null,
                }
            ],
            data: [
                {
                    name: "谢海燕",
                    age: 18,
                    sex: "女",
                    key:1
                },
                {
                    name: "朱艳敏",
                    age: 18,
                    sex: "女",
                    key:2
                },
                {
                    name: "申文静",
                    age: 19,
                    sex: "女",
                    key:3
                },
                {
                    name: "张梦潇",
                    age: 19,
                    sex: "女",
                    key:4
                },
                {
                    name: "董琳玥",
                    age: 18,
                    sex: "女",
                    key:5
                },
                {
                    name: "张子浩",
                    age: 20,
                    sex: "男",
                    key:6
                },
                {
                    name: "宋冰琦",
                    age: 18,
                    sex: "男",
                    key:7
                },
            ]
        }
    }
    render() {
        return (
            <div>
                <Table
                    rowClassName={() => 'editable-row'}
                    bordered
                    dataSource={this.state.data}
                    columns={this.state.columns}
                />
            </div>
        )
    }
    handleDelete = key => {
        const dataSource = [...this.state.data];
        this.setState({ data: dataSource.filter(item => item.key !== key) });
    };

}

export default Student;